import React, { Component, PropTypes } from 'react';
import { connect } from 'dva';
import { withRouter } from 'dva/router';
import { WhiteSpace, Carousel, Grid, Flex, Button,} from 'antd-mobile';
import styles from './styles.less';

const HealthyPage = (props) => {
  const pages = [{
    nextPathname: '/diagnosis',
    icon: require('../../assets/icons/icon-pick.svg'),
    text: '四诊采集',
  }, {
    nextPathname: '/scale_record',
    icon: require('../../assets/icons/icon-record.svg'),
    text: '测评记录',
  }, {
    nextPathname: '/archives',
    icon: require('../../assets/icons/icon-archives.svg'),
    text: '健康档案',
  }, {
    nextPathname: '/articles',
    icon: require('../../assets/icons/icon-health.svg'),
    text: '养生学堂',
  }, {
    nextPathname: '/foods',
    icon: require('../../assets/icons/icon-foods.svg'),
    text: '健康可餐',
  }, {
    href: 'http://tcmbaby.daosh.com/App/Manipulation/NavList',
    icon: require('../../assets/icons/icon-children.svg'),
    text: '小儿推拿',
  }];

  const pages1 = [{
    nextPathname: '/diagnosis',
    icon: require('../../assets/icons/icon-pick.svg'),
    text: '四诊采集',
  },{
    nextPathname: '/scale_record',
    icon: require('../../assets/icons/icon-record.svg'),
    text: '测评记录',
  },{
    nextPathname: '/archives',
    icon: require('../../assets/icons/icon-archives.svg'),
    text: '健康档案',
  },{
    nextPathname: '/foods',
    icon: require('../../assets/icons/icon-foods.svg'),
    text: '健康可餐',
  }];
  if(props.location.pathname="/"){
    props.location.pathname = "/healthy";
  }
  if(props.scale.url && props.scale.url.length == 1){
     props.scale.disabled = false;;
  }else{
     props.scale.disabled = true;;
  }
  const goto = (page = {}) => {
    if (page.nextPathname) {
      props.router.push({
        pathname: props.location.pathname + page.nextPathname,
        state: { title: page.text },
      });
    } else if (page.href) {
        window.location = page.href;
    }
  }; 
  
  let img = "sdf";
  // const pickImg = () =>{
  //   // 通过不同医院的hid来获取当前所展示的banner图列表
  //   if(sessionStorage.getItem('hid')){
  //     props.dispatch({
  //         type: 'scale/pickImg',
  //         payload: sessionStorage.getItem('hid'),
  //       });
  //     return img;
  //   }

  // };
  // goto();
  return (
    <div>
    <div style={{width: '100%',height: '5.1rem'}}>
      <Carousel
          autoplay={true}
          infinite={props.scale.disabled}
          className="my-carousel"
          swipeSpeed={35}
        >
        {props.scale.url
          ? props.scale.url.map((item) => {
              return( <div className={styles.slickslide}>
                  <img src={item}/>
               </div> 
              );
          }): ''
        }
        </Carousel>
        </div>
      {sessionStorage.getItem("hid") == 32 ?
        <Grid
              data={pages1}
              columnNum={2}
              onClick={(page, i) => goto(page)} />
        :<Grid
              data={pages}
              columnNum={2}
              onClick={(page, i) => goto(page)} />}
    </div>
  );
};

export default connect(({ scale }) => ({ scale }))(withRouter(HealthyPage));
